<?php
/*
 * Con_group 用户组权限管理
 * 2010-12-04
 * abans@qq.com
 */
//define('Acache_no','1');
class Con_group extends Acan{
	public $defaultAct='list';
	public $Conread = '用户组';
	public $Actread = array('list'=>'列表','save'=>'保存','add'=>'添加','del'=>'删除','power'=>'权限管理');
	function __construct($ainfo=null){
		parent::__construct($ainfo=null);
		$this->model = Afun_db()->model(Acan_table_group);
		$this->atitle = $this->Actread[$this->Aact];
	}
	//--列表
	function Act_list(){
		$this->model->enum['pid'] = Afunc_group()->enum();
		$obj = Afun_acan_new('list');
		$key_name = $this->model->key_name;
		$columnrr = $this->model->comment;//初始栏目
		unset($columnrr['admin']);
		$column = $obj->column($this->model,$columnrr,$_POST['acolumn']);
		$column_html = $obj->column_html($this->model,$column,'Aform');
		$column_json = $obj->form_json($this->model);
		//分页函数
		$con->where = "`appid`=".Acan_app_id;
		$con->select = "a.*";
		$page->theurl = $this->Aactr.'-'.$this->id;
		$page->by = $this->model->key_name;
		$page->page = '20';
		$page->counts = $this->model->count($con);	//统计总数目
		$pages = Afun_apage($page);
		$con->order = "a.$pages->orderby";
		$con->limit = $pages->limit;
		//分页结束
		$list = $this->model->findAll($con);
		include $this->Atpl();
	}
	//保存
	function Act_save(){
		Afun_post_auth();
		$savedata = $_POST['save'];
		if($this->id == 'one'){
			$key = $savedata[$this->model->key_name];
			unset($savedata[$this->model->key_name]);
			if(!empty($key)){
				$msg = $this->model->updatePk($savedata,$key);
			}else{
				$savedata['appid'] = Acan_app_id;
				$msg = $this->model->save($savedata);
			}
		}elseif(is_array($savedata)){
			foreach($savedata as $i=>$vals){
				$this->model->updatePk($vals,$vals['key']);
			}
		}
		Afunc_group()->delcache();
		Afun_json($msg);
	}
	//添加
	function Act_add(){
		Afun_post_auth();
		$_POST['add']['appid'] = Acan_app_id;
		if($this->model->save($_POST['add'])){
			Afun_refresh('添加成功','referrer');
		}else{Afun_refresh('添加失败','referrer');}
	}
	//删除
	function Act_del(){
		Afun_post_auth();
		if($this->model->deletePk($this->id)){
			echo '删除成功';
		}
	}
	//--列表
	function Act_power(){
		$gid = $_GET['gid'];
		$form_val_status = array('0'=>'无权限','1'=>'读取','2'=>'写入','3'=>'所有');
		$admin=0;
		if($_GET['admin']==1){
			$admin=1;
		}
		if($_POST){
			$save = $_POST['save'];
			echo Afunc_group()->power_save($gid,$save,$admin);
			Afun_refresh('更新成功','referrer');
		}
		$data = Afunc_group()->power_get($gid,$admin);
		$info = $this->model->find("gid=$gid and appid=".Acan_app_id);
		$list = Afunc_group()->getacts();
		$public = Afunc_group()->getacts('public');
		include $this->Atpl();
	}
}

?>